/**
 * @file e6_t2_q4.c
 * @date 2022-03-01
 * 
 * 
 * @copyright Copyright (c) 2022 cnzyx MIT Licence
 * 
 */

#include<stdio.h>
#include<stdlib.h>
#define N 5

typedef struct student
{
    char code[22];
    int score;
}student;

int minScore(student *array,student *result,int len){
    int min_score=array[0].score;
    int cnt=0;
    for(int i=0;i<len;i++){
        if (array[i].score<min_score){
            min_score=array[i].score;
        }
    }
    for(int i=0;i<len;i++){
        if(array[i].score==min_score){
            result[cnt++]=array[i];
        }
    }
    return cnt;
}

int main(int argc, char const *argv[])
{
    //UTF-8
    system("chcp 65001");

    student stu[N]={{"211230218",50},{"211230219",99},{"211230220",95},{"211230217",50},{"211230216",95}};
    student min_score[N];
    int cnt=minScore(stu,min_score,N);
    printf("分数最低的学生共%d个\n他们分别是：\n",cnt);
    for(int i=0;i<cnt;i++){
        printf("学号：%s，成绩：%3d \n",min_score[i].code,min_score[i].score);
    }
    
    //Pause console
    system("pause");
    return 0;
}
